package org.jspar.util;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;


public class ListUtil {

	public static <T, X> boolean isMember(X elem, T[] list,
			IPredicate<X, T> predicate) {
		List<T> l = new ArrayList<T>();
		Collections.addAll(l, list);
		return isMember(elem, l, predicate);
	}
	
	public static <T, X> boolean isMember(X elem, List<T> list,
			IPredicate<X, T> predicate) {
		for (T e : list) {
			if (predicate.test(elem, e))
				return true;
		}
		return false;
	}

	public static <T,X> List<T> member(X elem,
			List<T> list, IPredicate<X, T> predicate) {
		List<T> res = new ArrayList<T>();
		for (T e : list) {
			if (predicate.test(elem, e)) {
				res.add(e);
			}
		}
		return res;
	}

}
